﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WinLotto
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            cmbChooseGame.Items.Add(new SuomiLotto());
            cmbChooseGame.Items.Add(new VikingLotto());
            cmbChooseGame.Items.Add(new EurojackpotLotto());
            cmbChooseGame.SelectedIndex = 0;
            cmbChooseGame.ValueMember = "Name";

            updDrawCount.Maximum = 10;
            updDrawCount.Minimum = 1;
            updDrawCount.Increment = 1;
            updDrawCount.Value = 1;
        }

        private void drawButton_Click(object sender, EventArgs e)
        {
            int n = (int) updDrawCount.Value;

            for (int i = 0; i < n; i++)
            {
                var lotto = (Lotto)cmbChooseGame.SelectedItem;
                var name = lotto.Name;
                var draw = lotto.Draw();

                if (lotto is EurojackpotLotto) {
                    lstDraws.Items.Add(string.Format("{0}: {1}   **   {2}",
                        name,
                        draw.DelimitedString("   ", 0, 5),
                        draw.DelimitedString("   ", 5)));
                }
                else {
                    lstDraws.Items.Add(string.Format("{0}: {1}",
                        name,
                        draw.DelimitedString("   ")));
                }
            }

            lstDraws.SelectedIndex = lstDraws.Items.Count - 1;
        }

        private void clearButton_Click(object sender, EventArgs e)
        {
            lstDraws.Items.Clear();
        }

        private void closeButton_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
